package com.google.donutrush;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Services.Mailman;
import Services.UserService;
import Services.UserServiceDBimpl;


public class EmailVerServlet extends HttpServlet{
	
	
	public void doGet(HttpServletRequest request, HttpServletResponse response){

		String user = request.getParameter("user");
		String email = request.getParameter("email");
		String pswd = request.getParameter("pswd");
		System.out.println("user: "+ user + " email: "+ email + " pswd: " + pswd);
		
		UserService us = UserServiceDBimpl.getInstance();
		boolean ret = us.verifyUser(user, email, pswd);
		if (ret){
			Mailman.sendThanksMail("zzzoshri@gmail.com", email, user);
		}
		
		// Set page title
		String pageTitle = "Donut Rush Registration";
		
		 // Specify the content type is HTML
		 response.setContentType("text/html");
		 PrintWriter out=null;
		try {
			out = response.getWriter();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(out!=null){
			 // Generate the HTML response
			 out.println("<html>");
		     out.println("<head>");
			 out.println("<title>" + pageTitle + "</title>");
			 out.println("</head>");
			 out.println("<body>");
			
			 // Generate page heading
			 out.println("Thank you for your registration, you can now log-in and play, have fun!");
			 out.println("</br>");
			 out.println("<a href='http://apps.facebook.com/donut-rush/'>Play now!</a>");
			 out.println("</body>");
			 out.println("</html>");
		}

	}
}
